<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>可被三整除的偶数的平均值</title>
</head>
<body>
  <script>
    function fn(nums) {
      let total = 0, k = 0;
      for (let a of nums) {
        if (a % 6 === 0) {
          total += a;
          k++;
        }
      }
      return k > 0 ? Math.floor(total / k) : 0;
    }
    console.log(fn([1, 3, 6, 10, 12, 15]))
  </script>
</body>
</html>